home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / UUCP / UUNAME.C < prev    next >
C/C++ Source or Header  |  1992-11-15  |  7KB  |  209 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u n a m e . c                                                 */
  3. /*                                                                    */
  4. /*    Known site lister for UUPC/extended                             */
  5. /*                                                                    */
  6. /*--------------------------------------------------------------------*/
  7.  
  8. /*--------------------------------------------------------------------*/
  9. /*         System include files                                       */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <io.h>
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <fcntl.h>
  19. #include <stdlib.h>
  20.  
  21. /*--------------------------------------------------------------------*/
  22. /*         Local include files                                        */
  23. /*--------------------------------------------------------------------*/
  24.  
  25. #include "lib.h"
  26. #include "getopt.h"
  27. #include "hlib.h"
  28. #include "hostable.h"
  29. #include "security.h"
  30. #include "timestmp.h"
  31.  
  32. currentfile();
  33.  
  34. /*--------------------------------------------------------------------*/
  35. /*                             Verb list                              */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. typedef enum {
  39.    LIST_DEFAULT = 1,
  40.    LIST_LOCAL,
  41.    LIST_DOMAIN
  42.    } COMMAND_CLASS;
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*                        Internal prototypes                         */
  46. /*--------------------------------------------------------------------*/
  47.  
  48. static void all( void );
  49.  
  50. static void local( void );
  51.  
  52. static void domain( void );
  53.  
  54. static void usage( void );
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*    m a i n                                                         */
  58. /*                                                                    */
  59. /*    main program                                                    */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. void main(int  argc, char  **argv)
  63. {
  64.    int c;
  65.    COMMAND_CLASS command = LIST_DEFAULT;
  66.    extern char *optarg;
  67.    extern int   optind;
  68.  
  69. /*--------------------------------------------------------------------*/
  70. /*     Report our version number and date/time compiled               */
  71. /*--------------------------------------------------------------------*/
  72.  
  73.    debuglevel = 0;
  74.  
  75.    banner( argv );
  76.  
  77. #if defined(__CORE__)
  78.    copywrong = strdup(copyright);
  79.    checkref(copywrong);
  80. #endif
  81.  
  82. /*--------------------------------------------------------------------*/
  83. /*        Process our arguments                                       */
  84. /*--------------------------------------------------------------------*/
  85.  
  86.    while ((c = getopt(argc, argv, "dlx:")) !=  EOF)
  87.       switch(c) {
  88.       case 'x':
  89.          debuglevel = atoi( optarg );
  90.          break;
  91.  
  92.       case 'd':
  93.          command = LIST_DOMAIN;
  94.          break;
  95.  
  96.       case 'l':
  97.          command = LIST_LOCAL;
  98.          break;
  99.  
  100.       case '?':
  101.          usage();
  102.    }
  103.  
  104.    if (optind != argc) {
  105.       puts("Extra parameter(s) at end.");
  106.       exit(2);
  107.    }
  108.  
  109.    if (!configure( B_UUSTAT ))
  110.       exit(1);   /* system configuration failed */
  111.  
  112.    tzset();                      /* Set up time zone information  */
  113.  
  114. /*--------------------------------------------------------------------*/
  115. /*                   Execute the requested command                    */
  116. /*--------------------------------------------------------------------*/
  117.  
  118.    switch ( command )
  119.    {
  120.       case LIST_DEFAULT:
  121.              all( );
  122.              break;
  123.  
  124.       case LIST_LOCAL:
  125.              local( );
  126.              break;
  127.  
  128.       case LIST_DOMAIN:
  129.              domain( );
  130.              break;
  131.  
  132.       default:
  133.              panic();
  134.  
  135.    } /* switch */
  136.  
  137.    exit(0);
  138.  
  139. } /* main */
  140.  
  141. /*--------------------------------------------------------------------*/
  142. /*    a l l                                                           */
  143. /*                                                                    */
  144. /*    Display all connected systems names                             */
  145. /*--------------------------------------------------------------------*/
  146.  
  147. static void all( )
  148. {
  149.    struct HostTable *hostp = nexthost( TRUE );
  150.  
  151. /*--------------------------------------------------------------------*/
  152. /*                  Scan one or all host directories                  */
  153. /*--------------------------------------------------------------------*/
  154.  
  155.    while  (hostp !=  BADHOST )
  156.    {
  157.       printf("%s\n", hostp->hostname);
  158.  
  159. /*--------------------------------------------------------------------*/
  160. /*    If processing all hosts, step to the next host in the queue     */
  161. /*--------------------------------------------------------------------*/
  162.  
  163.       hostp = nexthost( FALSE );
  164.  
  165.    } /* while */
  166.  
  167. } /* all */
  168.  
  169. /*--------------------------------------------------------------------*/
  170. /*    l o c a l                                                       */
  171. /*                                                                    */
  172. /*    Display local systems node name                                 */
  173. /*--------------------------------------------------------------------*/
  174.  
  175. static void local( )
  176. {
  177.    printf("%s\n", E_nodename);
  178. } /* local */
  179.  
  180. /*--------------------------------------------------------------------*/
  181. /*    d o m a i n                                                     */
  182. /*                                                                    */
  183. /*    Display local systems domain name                               */
  184. /*--------------------------------------------------------------------*/
  185.  
  186. static void domain( )
  187. {
  188.    printf("%s\n", E_domain);
  189. } /* domain */
  190.  
  191. /*--------------------------------------------------------------------*/
  192. /*    u s a g e                                                       */
  193. /*                                                                    */
  194. /*    Report how to use program                                       */
  195. /*--------------------------------------------------------------------*/
  196.  
  197. static void usage( void )
  198. {
  199.  
  200.    fputs("Usage:\tuuname\t[-l|-d]\n\
  201. \tDefault is to display all known uucp systems.\n\
  202. \t-d\t\tDisplays local node's domain name.\n\
  203. \t-l\t\tDisplays local node's uucp name.\n",
  204.             stdout );
  205.  
  206.    exit(1);
  207.  
  208. } /* usage */
  209.